<template>
  <div>
    <span style="font-weight: bold">标题:</span>
    <el-input v-model="notice.title" placeholder="请输入标题" style="width: 150px;margin-left: 10px"></el-input>
    <el-button @click="goNoticeList" style="margin-left: 500px" type="primary" plain>返回列表</el-button>
    <div id="div1" style="padding-top: 10px">

    </div>
    <el-button type="primary" @click="addNotice" style="margin-top: 20px">添加</el-button>

  </div>

</template>

<script>
import E from "wangeditor"

export default {
  name: "NoticeAdd",
  data() {
    return {
      editor: null,
      notice: {}
    }
  },
  methods: {
    addNotice() {
      if (!this.notice.title) {
        this.$message.error("请输入标题");
        return;
      }
      if (!this.editor.txt.text()) {
        this.$message.error("请输入内容");
        return;
      }
      this.notice.content = this.editor.txt.html();
      this.axios.post("/notice/save", this.notice).then(resp => {
        if (resp.data.statusCode == 200) {
          this.$message({
            message: resp.data.message,
            type: 'success'
          });
          this.$router.replace("/system/noticeList");
        }
      })
    },
    goNoticeList() {
      this.$router.replace("/system/noticeList");
    }
  },
  mounted() {
    this.editor = new E("#div1")
    // 设置编辑区域高度为 350px
    this.editor.config.height = 270
    this.editor.create()
  }
}
</script>

<style lang="scss" scoped>

</style>
